local ActorManage = require("app.manage.ActorManage"):GetInstance()

local ActorBase = class("ActorBase", function()
	return display.newNode()
end)

function ActorBase:ctor(data)
--    print("ActorBase:ctor")
    self._Type = 0    --兵种
    self._property = { pos = {x=0,y=0} , }  --坐标
--    {type = 1 ,att = 1 , range = 5 ,speed = 100  }                           --攻击： type 攻击类型 ,att = 攻击力 , range = 攻击距离 ,speed = 攻击速度  
--    { hp = 100 ,speed = 50 , hatred = 100 , radius = 10 , weight = 100}             --身体素质： hp = 血上限 , speed = 移动速度 , hatred = 仇恨距离 , radius = 体积半径 weight = 体重，默认为半径的平方
    self._nowState = { }                         --当前状态： hp = 当前血量
    self._target = { pos = {} }  --目标：位置pos = {x=0,y=0} 指定攻击敌人 enemyAttack = id  指定仇恨敌人 enemyHatred = id
    self._player = 0
    self.isLive = true
    self.pow = {{},{},{}}    --力数组 ，每个数为pos格式
    self.pow.max = 0
    self.shift = {x=0,y=0} --主动移动属性
    if data then self:setData(clone(data)) end    
    self:enableNodeEvents()
end

function ActorBase:onEnter()
    self:CreateSprite()
end

function ActorBase:onExit()

end

function ActorBase:DeleteSelf()
--    self:remove
end

function ActorBase:CreateSprite()
--    print("ActorBase:CreateSprite")
    self.Sprite = display.newSprite("UI/actor/100.png")
    self.Sprite:scale(self._property.area_covered/50)    
    self.Sprite:addTo(self)
    self:move(self._property.pos)
    if self._property.color then 
        self.Sprite:setColor(self._property.color)
    elseif self._player==1 then 
        self.Sprite:setColor(cc.c4b(200,200,255,255))
    elseif self._player==2 then 
        self.Sprite:setColor(cc.c4b(255,200,200,255))
    end
    
    self.Head = display.newSprite("UI/actor/jianzhu.png")--self._property.head)
    self.Head:scale(self._property.area_covered/50)    
    self.Head:addTo(self)

    self.ID = td.CreateLabel(self.id,nil,16)
    self.ID:addTo(self)
end

function ActorBase:setData(data)
    for i, var in pairs(data) do
        self._property[i] = var
    end
    self._target.pos[1] = self._property.pos
end

function ActorBase:Update(dt)      

end

function ActorBase:CountMoveTo(pos,dt,Stand)
    Stand = Stand or false
    local speed = self._property.move_speed*dt
    local _pos = self:pos()

    local orientations = cc.pNormalize(cc.pSub(pos,_pos))

    local shift = {} 
    shift.x = speed * orientations.x
    shift.y = speed * orientations.y 
--    shift.sum = shift.x*shift.x + shift.y*shift.y

    self:SaveMove( shift.x , shift.y )
--    self:MoveTo( _pos.x + shift.x + repul.x , _pos.y + shift.y + repul.y  )
end

function ActorBase:SaveMove(x,y)
    self.shift={x=x,y=y}
--    self:SavePow(cc.pMul(self.shift,self:weight()),1)
end

function ActorBase:MoveTo(pos)
    self:move(pos.x,pos.y)
end

function ActorBase:pos()
    local _pos = {}
    _pos.x,_pos.y = self:getPosition()
    return _pos
end


return ActorBase